<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="bean.dal.*,bean.entity.*"%>
<%@page import="bean.common.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<jsp:include page="top.jsp"></jsp:include>
<br/><div align="center">
	 <fieldset style="width: 90%; margin: 0px auto;">
		<legend>
		     <font style="font-size:25px" face="宋体">
		          您接取的订单
		     </font>
		</legend>
	<table border="2" bordercolor="#e2d1c3" width="98%">
		<tr align="center" bordercolor="#e2d1c3">
			<td>订单号</td><td>姓名</td><td>电话</td><td>地址</td>
			<td>配送员</td><td>包裹类型<td>订单金额</td><td>订单状态</td>
			<td>下单日期</td><td>支付状态</td><td>订单备注</td>
			<td  colspan="1">操作</td>
			
		</tr>
		 <%
		String clerkid= (String) session.getAttribute("clerkid");
		if(clerkid==null) clerkid="123";
			 OrderManager orderM = new OrderManager();
			 Clerk clerk=new Clerk();
			 ClerkManager clerkM = new ClerkManager();
			 User user = new User();
			 UserManager userM=new UserManager();
			 
		    int pagesize = 15;//页面大小
		    int recordCount ;//记录总数
		    int pageCount;//页面总数
		    int pageid;//页面号
		    int newsTypeId=0;
		    String  strpageid = request.getParameter("pageid");
		    if(strpageid==null ) pageid=1;
		       else pageid = Integer.parseInt(strpageid); 
		    if(pageid < 1) pageid = 1;
    		recordCount =  orderM.getRecordCountByUser("clerkid", clerkid);
		    if(recordCount%pagesize==0) pageCount =  recordCount/pagesize ;
		      else pageCount =  recordCount/pagesize +1;
		    if(pageCount<=0) pageCount=1;
   			 if(pageid > pageCount) pageid=pageCount;
    		System.out.println(recordCount);
			 
		    //通过JavaBean的getUsersBypageid(pageid,pagesize)读取某页的记录数据
		  	ArrayList<Orders> orderslist=null;
		 	Iterator<Orders> it = null;
		 	Orders orders = null;
		    orderslist = orderM.getOrdersByUser(pageid, pagesize, "clerkid", clerkid);
		    //newsmanager.closeConn();//不再访问数据库，关闭连接
		    
		    //通过迭代器，列表显示每条记录，并做查看、删除链接
		 	if(orderslist!=null){	   it = orderslist.iterator();}
		 	
		 	while(it!=null&&it.hasNext()){
		 		orders =  it.next();
		 		user=userM.getUserByUserId(orders.getUserid());
		 		clerk=clerkM.getClerkByClerkId(orders.getClerkid());
		 %>
		<tr align="center" bordercolor="#e2d1c3">
			<td><%=orders.getOrderid() %></td><td><%=user.getUsername() %></td>
			<td><%=orders.getTel() %></td><td><%=orders.getLocation() %></td>
			<td><%=clerk.getClerkname() %></td><td><%=orders.getTypeid() %></td>
			<td><%=orders.getPrice() %></td><td><%=orders.getState() %></td>
			<td><%=orders.getOrderdate() %></td><td><%=orders.getPay_state() %></td>
			<td><%=orders.getBz() %></td>
			<td><a href="clerk/orderitem.jsp?id=<%=orders.getId()%>"><input type="button" value="查看"/></a></td>	
		</tr>
		<%} %>
		<tr align="center" bordercolor="#e2d1c3"><td colspan="13"><div>
		 <a href="clerk/order.jsp?pageid=1">第一页</a>&nbsp;
		 <a  href="clerk/order.jsp?pageid=<%=pageid-1 %>">上一页</a>&nbsp;
		   第<%=pageid %>页/共<%=pageCount %>页&nbsp;
		 <a  href="clerk/order.jsp?pageid=<%=pageid+1 %>">下一页</a>&nbsp;
		 <a  href="clerk/order.jsp?pageid=<%=pageCount %>">最后一页</a> 	 
		</div></td></tr>
	  </table><br/>
		 <a href="clerk/index.jsp">
		 	<input type="button" value="返回"/>
		 </a>
	  </fieldset>
	  </div>
  </body>
</html>
